CREATE PROCEDURE [dbo].[autoComplete_get_categories]
    @searchPattern nvarchar(256) = null
AS
if(@searchPattern is not null)
BEGIN
    SELECT DISTINCT TOP(20) 
        [dbo].[Categories].CategoryId,
        [dbo].[Categories].[Name]
    FROM [dbo].[Categories]
    WHERE [dbo].[Categories].[Name] LIKE '%' + @searchPattern + '%' 
END else
BEGIN
     SELECT TOP(20) 
        [dbo].[Categories].CategoryId,
        [dbo].[Categories].[Name]
     FROM [dbo].[Categories]
     ORDER BY [dbo].[Categories].[Name]
END

RETURN 0
